//
//  BasicView.m
//  美食百科
//
//  Created by dllo on 16/2/3.
//  Copyright © 2016年 doll. All rights reserved.
//

#import "BasicView.h"

@implementation BasicView

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"模式" object:nil];

    [_color release];

    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.frame = frame;
        //注册
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationAction:) name:@"模式" object:nil];
        
        NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
        
        BOOL night = [userDefaults boolForKey:@"夜间模式"];
        
        if (!night) {
            self.backgroundColor = [UIColor whiteColor];
            self.color = [UIColor blackColor];
        }else
        {
            self.backgroundColor = [UIColor colorWithRed:0.251 green:0.255 blue:0.412 alpha:1.00];
            self.color = [UIColor whiteColor];
           // self.alpha = 0.7;
        }
    }
    return self;
}
#pragma mark 接收消息时,执行的方法
-(void)notificationAction:(NSNotification *)notification
{
    NSString *mode = notification.userInfo[@"Mode"];
    
    if ([mode isEqualToString:@"白天"]) {
        self.backgroundColor = [UIColor whiteColor];
        self.color = [UIColor blackColor];
        self.alpha = 1;
        [self setNeedsDisplay];
    }else
    {
        self.backgroundColor = [UIColor colorWithRed:0.251 green:0.255 blue:0.412 alpha:1.00];
        self.color = [UIColor whiteColor];
       // self.alpha = 0.7;
        [self setNeedsDisplay];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
